import time, gc
import esp_net as en
from ILI9431c import ILI9341
from machine import Pin, SoftSPI

LCD_WIDTH = 240
LCD_HEIGHT = 320

#esp32s3管脚
spi = SoftSPI(
    baudrate=800000,
    mosi = Pin(11),
    miso = Pin(13),
    sck=Pin(12)
    )

display = ILI9341(
    spi,
    cs=Pin(8),
    dc=Pin(6),
    rst=Pin(5),
    bl=Pin(7),
    w=240,
    h=320,
    r=0)


# 内存回收，防止数据溢出
def mem_recov():
    size = gc.mem_alloc()
    men_size = gc.mem_free()
    if size > (men_size // 2):
        gc.collect()

# 连接热点，全为默认值
en.start()

def fun():
    udp_sock = en.server(mode = "UDP",addr = ('0.0.0.0', 7788))
    
    while True:
        display.bitmap_udp(0, 0, LCD_WIDTH, LCD_HEIGHT, udp_sock)
        mem_recov()
        
    
if __name__ == '__main__':
    gc.enable()
    fun()
    












